package com.wms.dao.impl;

import com.wms.dao.UserDao;
import com.wms.model.User;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author This
 * @version 1.0
 * @date 2019/7/10 11:02
 */
@Repository
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao {
    @Override
    public boolean hasUser() {
        String hql = "select count(id) from User where username <> 'admin'";
        long count = (Long) this.template.find(hql).listIterator().next();
        return count > 0;
    }

    /*@Override
    public Long count() {
        String hql = "select count(id) from User";
        return (Long) this.template.find(hql).listIterator().next();
    }*/

    @SuppressWarnings("unchecked")
    @Override
    public User findOne(String username, String password) {
        String hql = "from User where username = ? and password = ?";
        List<User> list = this.template.find(hql, username, password);
        if (list.size() == 1) {
            return list.get(0);
        }
        return null;
    }
}
